package a_arrays;

//自定义类型
public class Student implements Comparable<Student>{
    private String name;
    private double height;
    private int age;

    public Student() {
    }

    public Student(String name, double height, int age) {
        this.name = name;
        this.height = height;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", height=" + height +
                ", age=" + age +
                '}';
    }

    //重写后的方法 -> 自定义比较规则
    //this o 做对比
    /*
        左边对象 大于 右边对象 返回正整数
        左边对象 小于 右边对象 返回负整数
        左边对象 等于 右边对象 返回0
     */
    @Override
    public int compareTo(Student o) {
        /*if (this.age > o.age){
            return 1;
        }else if (this.age < o.age){
            return -1;
        }
        return 0;*/
        //下边是优化以上代码的写法
        return this.age - o.age; //按照年龄升序排序
        //return o.age - this.age;//降序排序
    }
}
